
import 'package:flutter/material.dart';
import 'package:ruitmentapp/personnel/model/zj_home_model.dart';
import 'package:ruitmentapp/core/extension/int_extension.dart';
import 'package:provider/provider.dart';
import 'package:ruitmentapp/personnel/zj_tabbar_two_list_detail_page.dart';

final cardRadius = 12.px;

class ZJListPageItem extends StatelessWidget {

  final ZJHomePositionModel _meal;
  ZJListPageItem(this._meal);

  @override
  Widget build(BuildContext context) {
    backgroundColor: const Color(0xFFF3F5F7);
    return GestureDetector(
      child: Card(
        margin: EdgeInsets.only(left: 20.px, right: 20.px, bottom: 10.px),
        elevation: 0.0,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(cardRadius)),
        child: Column(
          children: <Widget>[
            buildPushTitleInfo(context),
            buildAdressInfo(context),
            buildBasicInfo(context),
            buildOperationInfo(context),
          ],
        ),
      ),
      onTap: (){
        Navigator.of(context).pushNamed(ZJTabbarTwoListDetailPageScreen.routeName, arguments: _meal);
      },
    );
  }

  Widget buildPushTitleInfo(BuildContext context) {

    String title = _meal.startSalary == 100.0 ? "100k以上": '${_meal.startSalary.toInt()}-${_meal.endSalary.toInt()}K';
    return Row(
      children: [
        Expanded(child:
          Padding(
            padding: const EdgeInsets.only(top: 20, left: 15, right: 15),
            child: Text(_meal.pushTitle,
                textAlign:TextAlign.left,
                style: const TextStyle(
                    color: Color(0xFF3F4756),
                    fontSize: 18,
                    fontWeight: FontWeight.bold)),
          ),
        ),
        // Expanded(child:
          Padding(
            padding: const EdgeInsets.only(top: 20, left: 15, right: 15),
            child: Text(title,
                textAlign:TextAlign.right,
                style: const TextStyle(
                    color: Color(0xFF5D55FC),
                    fontSize: 16)),
          ),
        // )
      ],
    );
  }

  Widget buildAdressInfo(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(top: 5, left: 15, right: 15),
      child: Row(
        children: [
          Text(_meal.countyName,
              textAlign:TextAlign.left,
              style: const TextStyle(
                  color: Color(0xFF77809E),
                  fontSize: 12
              )
          ),
        ],
      ),
    );
  }

  Widget buildBasicInfo(BuildContext context) {

    String workYear = '';
    if(_meal.workYear.contains("年")){
      workYear = _meal.workYear;
    }else {
      if (_meal.workYear.contains("不限")) {
        workYear = "经验不限";
      }else {
        workYear = '${_meal.workYear}年';
      }
    }

    List rangAry = ["学历不限","初中及以下","中专/中技","高中","大专","本科","硕士","博士"];
    String endution = rangAry[_meal.education];

    List array = [workYear, endution];
    List <Widget> textArray = [];

    for(var item in array){
      textArray.add(
        Card(
            elevation: 0.0,//设置阴影，即card在z轴的距离，数字越大阴影越重
            color: const Color(0xFFF3F5F7),//设置颜色，数字为颜色饱和度
            shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(3.0))),
            child: Container(
                padding: const EdgeInsets.only(left: 10, top: 3, bottom: 3, right: 10),
                child: Text(item, style: const TextStyle(color: Color(0xFF77809E),fontSize: 12))
            ),
        )
      );
    }

    return Container(
      color: Colors.white,
      width: MediaQuery.of(context).size.width - 70,
      height: 40,
      margin: EdgeInsets.all(8.px),
      child: Row(
        children: textArray,
      ),
    );
  }

  Widget buildOperationInfo(BuildContext context) {

    String url = _meal.logo ?? "https://prod.avatars.img.hr100.xin/2021-01/44A3DB4DF31046F6B06A0D6CCB1507D0_300.jpg";
    url = url.contains('http') ? url:"https://prod.avatars.img.hr100.xin/2021-01/44A3DB4DF31046F6B06A0D6CCB1507D0_300.jpg";

    return Row(
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(left: 15, bottom: 15),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(12.px),
              child: Image.network(
                url,
                width: 25.px,
                height: 25.px,
              ),
            ),
          ),
          Expanded(child:
            Padding(
              padding: const EdgeInsets.only(left: 10, bottom: 15),
              child: Text(_meal.referredName, style: const TextStyle(color: Color(0xFF77809E),fontSize: 14)),
            ),
          ),
          _meal.pushType == 2 ? pushType2Info():Container(),
          _meal.pushType == 3 ? pushType3Info():Container(),
        ]
    );
  }

  Widget pushType2Info() {
    return Padding(
      padding: const EdgeInsets.only(left: 10, bottom: 15,right: 0),
      child: Card(
        elevation: 0.0,//设置阴影，即card在z轴的距离，数字越大阴影越重
        color: const Color(0xFFFFF4F2),//设置颜色，数字为颜色饱和度
        shape: const RoundedRectangleBorder(borderRadius: BorderRadius.only(topLeft: Radius.circular(10.0), bottomLeft: Radius.circular(10.0))),
        child: Container(
          padding: const EdgeInsets.only(left: 0, top: 3, bottom: 3, right: 10),
          child: Row(
            children: [
              Image.asset("assets/images/home/homejipin.png", width: 22, height: 22),
              const Text(' 投递简历得', style: TextStyle(color: Color(0xFFFF5050),fontSize: 12)),
              Image.asset("assets/images/home/homemoneyred.png", width: 12, height: 16),
              Text('*${_meal.bonusAmount.toInt()}', style: const TextStyle(color: Color(0xFFFF5050),fontSize: 12)),
            ],
          ),
        ),
      ),
    );
  }

  Widget pushType3Info() {
    return Padding(
      padding: const EdgeInsets.only(left: 10, bottom: 15,right: 0),
      child: Card(
        elevation: 0.0,//设置阴影，即card在z轴的距离，数字越大阴影越重
        color: const Color(0xFFFFF3EF),//设置颜色，数字为颜色饱和度
        shape: const RoundedRectangleBorder(borderRadius: BorderRadius.only(topLeft: Radius.circular(10.0), bottomLeft: Radius.circular(10.0))),
        child: Container(
          padding: const EdgeInsets.only(left: 0, top: 3, bottom: 3, right: 10),
          child: Row(
            children: [
              Image.asset("assets/images/home/homeshang.png", width: 22, height: 22),
              Text(' 悬赏总额公示 ￥${_meal.rewardAmount.toInt()}', style: const TextStyle(color: Color(0xFFFF8F6B),fontSize: 12)),
            ],
          ),
        ),
      ),
    );
  }
}